package com.atguigu.srb.oss.cotroller;

import com.atguigu.guigu.common.result.R;
import com.atguigu.srb.oss.cotroller.service.OssService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/oss")
public class OssController {
    @Resource
    OssService ossService ;
    //http://srb220718.oss-cn-shanghai.aliyuncs.com/weige/2022/11/25/1669360623433_dda09c.gif
    @ApiOperation("文件删除")
    @DeleteMapping("delete")
    public R deleteFile(@RequestParam("path")String path){
        ossService.deleteFile(path);
        return R.ok().message("文件删除成功");
    }
    @ApiOperation("文件上传")
    @PostMapping("upload")
    public R upload(MultipartFile file ,String module){
        String imgUrl = ossService.upload(file,module);
        return R.ok().data("path",imgUrl);
    }

}
